package net.hn.hnms.biz.indicator.service;

import cn.hutool.core.convert.Convert;
import lombok.RequiredArgsConstructor;
import net.hn.hnms.biz.indicator.dao.SysIndicatorBaseDataMapper;
import net.hn.hnms.biz.indicator.entity.IndicatorBaseDataVO;
import net.hn.hnms.biz.indicator.entity.SysIndicatorBaseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author 智呈物联 nzw
 * @date 2022/9/19
 */
@Service
@RequiredArgsConstructor
public class SysIndicatorBaseDataService {

    SysIndicatorBaseDataMapper sysIndicatorBaseDataMapper;
    private final JdbcTemplate locationJdbcTemplate;

    @Autowired
    public void setSysIndicatorBaseDataMapper(SysIndicatorBaseDataMapper sysIndicatorBaseDataMapper) {
        this.sysIndicatorBaseDataMapper = sysIndicatorBaseDataMapper;
    }

    public List<IndicatorBaseDataVO> allList(){
        List<Map<String,Object>> baseData = sysIndicatorBaseDataMapper.queryAllByDataStatus();
        List<IndicatorBaseDataVO> vos = Convert.toList(IndicatorBaseDataVO.class, baseData);
        return vos;
    }

    public boolean updateById(SysIndicatorBaseData sysIndicatorBaseData){
        String sql = "UPDATE ssys_indicator_base_data SET indicator_value = '" +sysIndicatorBaseData.getIndicatorValue()+"'"+
                " WHERE\n" +
                "\tID = "+sysIndicatorBaseData.getId();
        locationJdbcTemplate.execute(sql);
        return true;
    }
}
